//
//  YJBaseViewController.swift
//  YJBaseProject
//
//  Created by 冯垚杰 on 2017/10/16.
//  Copyright © 2017年 冯垚杰. All rights reserved.
//

import UIKit

class YJBaseViewController: UIViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()

        view.backgroundColor = .white
        
        self.navigationController?.navigationBar.isTranslucent = false
        
        setupUI()
        setupNavigationBar()
    }
    
    override  open func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        view.endEditing(true)
    }
    
    func setupUI() {
        print("设置UI")
    }

    func setupNavigationBar() {
        print("设置导航条")
    }
    
    @objc func backViewController() {
        
        self.view.endEditing(true)
        
        // 根据viewControllers的个数来判断此控制器是被present的还是被push的
        if let viewControllers = navigationController?.viewControllers {
            
            if let index = viewControllers.index(of: self) {
                if viewControllers.count >= 1 && index > 0 {
                    navigationController?.popViewController(animated: true)
                    return
                }
            }
        }
        
        dismiss(animated: true, completion: nil)
    }
    
    deinit {
        print("\(classForCoder) deinit");
    }
}

